// let EventEmitter = require('events')
//
// let e = new EventEmitter();
// e.on('吃饭',()=>{
//   console.log('吃米饭')
// })
//
//
//
//
// e.emit('吃饭')
class EventEmitter {
  constructor(){
    this._events={}


  }
  on(eventName,callback){
    if (this._events[eventName]){
      this._events[eventName].push(callback);
    }else {
      this._events[eventName]=[callback];
    }
  }
  emit(eventName){
    this._events[eventName].forEach(fn=>{
      fn();
    })
  }
  off(eventName,callback){
    this._events[eventName] = this._events[eventName].filter((fn)=>{
      return fn!==callback;
    })
  }
}
let e = new EventEmitter();
e.on('吃饭',()=>{
  console.log('吃米饭')
})
let fn = ()=>{
  console.log('吃肉')
};
e.on('吃饭',fn)


e.off('吃饭',fn)

e.emit('吃饭')
